package com.bzg.manager.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bzg.manager.bean.ContainerInfo;
import com.bzg.manager.bean.HisStockInfo;
import com.bzg.manager.bean.OSDInfo;
import com.bzg.manager.bean.RecInfo;
import com.bzg.manager.bean.SendInfo;
import com.bzg.manager.bean.StockInfo;
import com.bzg.manager.bean.WHInfo;
import com.bzg.manager.exception.BaseExceptionTool;
import com.bzg.manager.param.BusiQueryParam;
import com.bzg.manager.service.QueryCenterService;
import com.bzg.manager.utils.PageBean;
import com.bzg.manager.utils.RespBody;
import com.wordnik.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/api/queCenter")
public class QueryCenterController extends BaseController{
	
	public static final Logger log = LoggerFactory.getLogger(QueryCenterController.class);
	
	@Autowired
	private QueryCenterService queryCenterService;
	
	@RequestMapping(value="/getRecInfo",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="收货信息查询")
	public RespBody getRecInfo(@RequestBody JSONObject json){
		BusiQueryParam param = JSON.toJavaObject(json.getJSONObject("info"), BusiQueryParam.class);
		if(param == null || StringUtils.isEmpty(param.getVendCode()) 
					|| param.getStartDate() == null || param.getEndDate() == null){//查询条件为空时抛出异常
			throw BaseExceptionTool.PARAM_IS_NULL;
		}
		//目前不实现分页功能，将分页信息设为null
		param.setCurrPage(null);
		param.setPageSize(null);
		
		PageBean<RecInfo> pageBean = queryCenterService.getRecInfo(param);
		
		return RespBody.ok(pageBean);
	}
	
	@RequestMapping(value="/getStockInfo",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="库存信息查询")	
	public RespBody getStockInfo(@RequestBody JSONObject json){
		BusiQueryParam param = JSON.toJavaObject(json.getJSONObject("info"), BusiQueryParam.class);
		if(param == null || StringUtils.isEmpty(param.getVendCode()) 
				|| param.getDate() == null || StringUtils.isEmpty(param.getwHCode())){//查询条件为空时抛出异常
		throw BaseExceptionTool.PARAM_IS_NULL;
		}
		//目前不实现分页功能，将分页信息设为null
		param.setCurrPage(null);
		param.setPageSize(null);
		
		PageBean<StockInfo> pageBean = queryCenterService.getStockInfo(param);
		return RespBody.ok(pageBean);
	}
	
	@RequestMapping(value="/getHisStockInfo",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="历史库存信息查询")	
	public RespBody getHisStockInfo(@RequestBody JSONObject json){
		BusiQueryParam param = JSON.toJavaObject(json.getJSONObject("info"), BusiQueryParam.class);
		if(param == null || StringUtils.isEmpty(param.getVendCode()) 
				|| param.getStartDate() == null || param.getEndDate() == null){//查询条件为空时抛出异常
		throw BaseExceptionTool.PARAM_IS_NULL;
		}
		//目前不实现分页功能，将分页信息设为null
		param.setCurrPage(null);
		param.setPageSize(null);
		
		PageBean<HisStockInfo> pageBean = queryCenterService.getHisStockInfo(param);
		return RespBody.ok(pageBean);
	}
	
	@RequestMapping(value="/getSendInfo",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="发运信息查询")	
	public RespBody getSendInfo(@RequestBody JSONObject json){
		BusiQueryParam param = JSON.toJavaObject(json.getJSONObject("info"), BusiQueryParam.class);
		if(param == null || StringUtils.isEmpty(param.getVendCode()) || StringUtils.isEmpty(param.getwHCode())
				|| param.getStartDate() == null || param.getEndDate() == null){//查询条件为空时抛出异常
		throw BaseExceptionTool.PARAM_IS_NULL;
		}
		//目前不实现分页功能，将分页信息设为null
		param.setCurrPage(null);
		param.setPageSize(null);
		PageBean<SendInfo> pageBean = queryCenterService.getSendInfo(param);
		return RespBody.ok(pageBean);
	}
	
	@RequestMapping(value="/getAllWh",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="查询所有仓库")	
	public RespBody getAllWh(@RequestBody JSONObject json){
		
		List<WHInfo> allWh = queryCenterService.getAllWh();
		
		return RespBody.ok(allWh);
	}
	
	@RequestMapping(value="/getContInfo",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="查询容器信息")	
	public RespBody getContInfo(@RequestBody JSONObject json){
		BusiQueryParam param = JSON.toJavaObject(json.getJSONObject("info"), BusiQueryParam.class);
		if(param == null || StringUtils.isEmpty(param.getVendCode()) || StringUtils.isEmpty(param.getwHCode())
								|| StringUtils.isEmpty(param.getCaseType()) || param.getStartDate() == null 
								|| param.getEndDate() == null){//查询条件为空时抛出异常
		throw BaseExceptionTool.PARAM_IS_NULL;
		}
		//目前不实现分页功能，将分页信息设为null
		param.setCurrPage(null);
		param.setPageSize(null);
		PageBean<ContainerInfo> pageBean = queryCenterService.getContInfo(param);
		return RespBody.ok(pageBean);
	}
	
	@RequestMapping(value="/getOSDInfo",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="查询OSD信息")	
	public RespBody getOSDInfo(@RequestBody JSONObject json){
		BusiQueryParam param = JSON.toJavaObject(json.getJSONObject("info"), BusiQueryParam.class);
		if(param == null || StringUtils.isEmpty(param.getVendCode()) || StringUtils.isEmpty(param.getwHCode())
				|| param.getStartDate() == null || param.getEndDate() == null){//查询条件为空时抛出异常
		throw BaseExceptionTool.PARAM_IS_NULL;
		}
		PageBean<OSDInfo> pageBean = queryCenterService.getOSDInfo(param);
		return RespBody.ok(pageBean);
	}
}
